const { getList,getNew} = require("../controller/blog")
const {SuccessModedl}=require('../model/resModel')

const handleBlogRouter = (req, res) => {
    if (req.method==='GET' && req.path==='/api/fsh/list') {
        const author=req.query.author || '';
        const keyword=req.query.keyword || '';
        const getlist= getList(author,keyword)
       return getlist.then(listdata=>{
        return new SuccessModedl(listdata)
       })
       
    }
    // 新建
    if (req.method==='POST' && req.path==='/api/blog/new') {
        
        const getnew= getNew(req.body)
       return getnew.then(newdata=>{
        return new SuccessModedl({
            id:newdata.insertId
        })
       })
       
    }
}

module.exports=handleBlogRouter